﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Common;

public partial class system_frmsystemcatalogtree : PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Expires = -1;

        LoadSystemCatalogTree();

        divTreeContainer.InnerHtml = TREE.ToString();

    }

    protected StringBuilder TREE = null;
    void LoadSystemCatalogTree()
    {
        TREE = new StringBuilder();

        string SQL = " AND DeletionStateCode = 0";
        string catalogids = RequestBase.GetQueryString("catalogids");

        if (catalogids.Trim() != "")
            SQL = " AND CatalogId IN (SELECT CatalogId FROM System_CatalogBase WHERE CatalogId NOT IN (" + catalogids + ")) ";

        DataTable dat = BLL.CommonBLL.Select("System_CatalogBase", " * ", SQL + " ORDER BY Sort ASC ");
        if (dat != null && dat.Rows.Count > 0)
            SystemCatalogTree(1, "0", dat);

        dat.Dispose(); 
    }

    void SystemCatalogTree(int intLayer, string parentId, DataTable dt)
    {
        string HTML_ITEMS = "<li class=\"simpleTree\" itemId=\"{0}\"><span class=\"simpleTree\"><a class=\"simpleTree\" href=\"###\"><img class=\"simpleTree\" src=\"../_imgs/{2}\" /></a><label class=\"TreeItem\" for=\"{0}\">{1}</label></span></li>";

        DataRow[] dr = dt.Select("Layer = " + intLayer.ToString() + " AND ParentId = " + parentId);

        TREE.Append("<ul class=\"simpleTree\">");
        int intCatalogLayerId = 0;
        foreach (DataRow d in dr)
        {
            intCatalogLayerId = int.Parse(d["Layer"].ToString());

            TREE.Append(string.Format(HTML_ITEMS, d["CatalogId"].ToString(), d["CatalogName"].ToString(), (d["IsChildNote"].ToString() == "1") ? "ico_Dot.gif" : "ico_Minus.gif"));

            SystemCatalogTree(intCatalogLayerId + 1, d["CatalogId"].ToString().Trim(), dt);
        }
        TREE.Append("</ul>");
    }
}
